package leetcode.medium.limit100;

/**
 * @author yaoyao1.liu@zhaopin.com.cn
 * @since 2022-11-11 14:06
 **/
public class No74 {
    public static void main(String[] args) {
        No74 no74 = new No74();
        int[][] matrix = new int[][]{{1, 3, 5, 7}, {10, 11, 16, 20}, {23, 30, 34, 60}};

        boolean searchMatrix = no74.searchMatrix(matrix, 13);
        System.out.println(searchMatrix);

    }

    public boolean searchMatrix(int[][] matrix, int target) {
        boolean flag = false;
        Integer first = null;
        for (int i = 0; i < matrix.length; i++) {
            for (int i1 = 0; i1 < matrix[i].length; i1++) {
                if (matrix[i][i1] == target) {
                    flag = true;
                }
                if (first == null) {
                    first = matrix[i][i1];
                    continue;
                }
                if (matrix[i][i1] < first) {
                    return false;
                }
                first = matrix[i][i1];
            }
        }
        return flag;
    }
}
